<?php

namespace app\common\model;

use think\Model;


class Acct extends Model
{

    

    

    // 表名
    protected $name = 'acct';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'admin_name'
    ];
    

    







    public function admin()
    {
        return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function getAdminNameAttr($value, $data)
    {
        if(isset($data['admin']['nickname'])){
            return $data['admin']['nickname'];
        }else{
            if(isset($data['admin_id'])){
                $admin = Admin::get($data['admin_id']);
                return !empty($admin['nickname'])?$admin['nickname']:'';
            }else{
                return '';
            }
        }
    }
}
